﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLV.Data.Entities;
using DLV.FrameWork;

namespace DLV.BackEnd.Pages
{
    public partial class ChietTinhQuaTang : AdminPageBase
    {
        protected List<CalculatorInfo> GiftsList = new List<CalculatorInfo>();
        protected decimal TotalGiftsPrices = 0;
        protected decimal TotalGiftsPricesAdults = 0;
        protected decimal TotalGiftsPricesChild = 0;
        protected decimal TotalGiftsPricesBaby = 0;
        protected decimal TotalVatGifts = 0;

        private List<CalculatorInfo> _calculatorList = new List<CalculatorInfo>();
        private readonly CalculatorController _calculatorController = new CalculatorController();
        protected TourInfo tourInfo = new TourInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["TourId"]))
            {
                _calculatorList =
                    _calculatorController.ListCalculator()
                        .Where(p => p.TourId == int.Parse(Request.QueryString["TourId"])).ToList();
                tourInfo = new TourController().GetTour(int.Parse(Request.QueryString["TourId"]));
            }
            LoadGiftsType();
            if (_calculatorList.Count == 0) return;
            RenderForm();
        }

        public void RenderForm()
        {

            if (!String.IsNullOrEmpty(Request.QueryString["TourId"]))
            {
                GiftsList = _calculatorList.Where(p => p.ItemType == 13).ToList();
                TotalGiftsPrices = GiftsList.Sum(p=>p.TotalPriceGifts);
                TotalGiftsPricesAdults = GiftsList.Sum(p => p.TotalPriceAdultsGifts);
                TotalGiftsPricesChild = GiftsList.Sum(p => p.TotalPriceChildGifts);
                TotalGiftsPricesBaby = GiftsList.Sum(p => p.TotalPriceBabyGifts);
                TotalVatGifts = (decimal)GiftsList.Sum(p => p.Vat);
            }
        }

        public void LoadGiftsType()
        {
            ddlGiftsType.DataSource = new GiftsTypeController().ListGiftsType().OrderBy(p => p.GiftsTypeName);
            ddlGiftsType.DataValueField = "GiftsTypeId";
            ddlGiftsType.DataTextField = "GiftsTypeName";
            ddlGiftsType.DataBind();

            ddlGiftsType.Items.Insert(0, new ListItem("--Chọn loại quà--", "-1"));

        }
    }
}